home *** CD-ROM | disk | FTP | other *** search
- Path: lade.news.pipex.net!pipex!dircon!usenet
- From: topher@dircon.co.uk (Chris Pyman)
- Newsgroups: comp.lang.c++
- Subject: Memory Leak?
- Date: Tue, 12 Mar 1996 12:16:58 GMT
- Organization: Direct Connection
- Message-ID: <4i2tr9$q6k@newsgate.dircon.co.uk>
- NNTP-Posting-Host: gw2-157.pool.dircon.co.uk
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hi all
-
- Does anybody know whether the following would lead to a memory leak?
- (Assume this is a Win32 Console App written with Visual C++ v2.0)
-
-
- main(int argc, char* argv[]) {
- CString s1("31-12-99");
- CString s2;
-
- s2 = s1.Mid(0,2) + s1.Mid(3,2) + s1.Mid(6,2);
-
- cout << s2;
- return 0;
- }
-
-
- Obviously the idea is to set s2 to "311299", but I would have thought
- that the Mid() method creates a new CString object and returns a
- reference to it, in which case what becomes of the three "temporary"
- objects used to build the string in s2? Are they just floating around
- with no way to get at them, or do they get properly deleted? And if
- the latter, how does MFC manage it?
-
- The main reason I'm asking this is because I want to implement a
- string class of my own, and would like to be able to use it to build
- strings as simply as shown above, but I don't want loads of stray
- objects floating around.
- Oh, and before you ask, no I can't just use MFC because my programs
- have to run on OS/2 as well as Win32. So I have to stick to
- standard-library stuff, and any classes I use have to be my own.
-
- Looking forward to hearing from you
- Sorry if I'm being ignorant or dimwitted, but I've only read as much
- of Stroustrup's book as my puny brain can take in at the moment.
-
- l+k
- chris
-
-
-